package classesInterface;

import classesBancodeDados.FichaAtendPsiqUrgencia;
import classesBancodeDados.Paciente;
import classesJpa.FichaAtendPsiqUrgenciaJpaController;
import classesJpa.exceptions.NonexistentEntityException;
import classesMiolo.AplicacaoUrgencia;
import classesMiolo.Formatador;
import classesMiolo.MapasAtendPsiqUrgencia;
import classesMiolo.ReverseMapper;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

public class TelaFichaAtendPsiqUrgencia2 extends javax.swing.JFrame {

    /**
     * Creates new form AtendPsiqUrgencia2
     */
    private TelaFichaAtendPsiqUrgencia2() {
        initComponents();
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
    
    public static TelaFichaAtendPsiqUrgencia2 getInstance(){
        if(instance == null) instance = new TelaFichaAtendPsiqUrgencia2();
        return instance;
    }
    
    public void limpaCampos(){
        this.areaEvoMedica.setText("");
        this.areaEvoPsico.setText("");
        this.areaEvoSocial.setText("");
        this.areaHorario.setText("");
        this.areaPrescricao.setText("");
        this.areaProc.setText("");
        this.campoConduta.setText("");
        this.campoDataEvoMedica.setText("");
        this.campoDataEvoSocial.setText("");
        this.campoDataEvoPsico.setText("");
        this.campoDiag.setText("");
        this.campoHoraEvoMedica.setText("");
        this.campoHoraEvoPsico.setText("");
        this.campoHoraEvoSocial.setText("");
        DefaultTableModel d1 = (DefaultTableModel)this.tableQtd.getModel();
        while(this.tableQtd.getRowCount() > 0){
            d1.removeRow(0);
        }
        this.comboDestino.setSelectedIndex(0);
    }
    
    public void preencherCampos(Paciente p, FichaAtendPsiqUrgencia apu){
        this.areaEvoMedica.setText(apu.getEvMedica().getEvolucao());
        this.areaEvoPsico.setText(apu.getEvPsicologia().getEvolucao());
        this.areaEvoSocial.setText(apu.getEvServSoc().getEvolucao());
        this.areaHorario.setText(apu.getHorMedicacao());
        this.areaPrescricao.setText(apu.getPrescricao());
        this.areaProc.setText(apu.getProcRealizado());
        this.campoConduta.setText(apu.getConduta());
        this.campoDataEvoMedica.setText(apu.getEvMedica().getData());
        this.campoDataEvoSocial.setText(apu.getEvServSoc().getData());
        this.campoDataEvoPsico.setText(apu.getEvPsicologia().getData());
        this.campoDiag.setText(apu.getDiagnostico());
        this.campoHoraEvoMedica.setText(apu.getEvMedica().getHora());
        this.campoHoraEvoPsico.setText(apu.getEvPsicologia().getHora());
        this.campoHoraEvoSocial.setText(apu.getEvServSoc().getHora());
        DefaultTableModel d1 = (DefaultTableModel)this.tableQtd.getModel();
        for(AplicacaoUrgencia au : ficha.getAplic()){
            String[] aux = new String[5];
            aux[0] = au.getQuant() + "";
            aux[1] = au.getMedic();
            aux[2] = au.getDose();
            aux[3] = au.getHora();
            aux[4] = au.getEvolucao();
            d1.addRow(aux);
        }
        MapasAtendPsiqUrgencia mapa = MapasAtendPsiqUrgencia.getInstance();
        this.comboDestino.setSelectedItem(ReverseMapper.getKeyFromValue(mapa.getDestino(), ficha.getDestino()));
    }
    
    public void turnEditable(boolean editable){
        botaoSalvar.setEnabled(editable);
        this.areaEvoMedica.setEditable(editable);
        this.areaEvoPsico.setEditable(editable);
        this.areaEvoSocial.setEditable(editable);
        this.areaHorario.setEditable(editable);
        this.areaPrescricao.setEditable(editable);
        this.areaProc.setEditable(editable);
        this.campoConduta.setEditable(editable);
        this.campoDataEvoMedica.setEditable(editable);
        this.campoDataEvoSocial.setEditable(editable);
        this.campoDataEvoPsico.setEditable(editable);
        this.campoDiag.setEditable(editable);
        this.campoHoraEvoMedica.setEditable(editable);
        this.campoHoraEvoPsico.setEditable(editable);
        this.campoHoraEvoSocial.setEditable(editable);
        this.comboDestino.setEnabled(editable);
        this.tableQtd.setEnabled(editable);
    }
    
    private void salvar(){
        ficha.getEvMedica().setEvolucao(this.areaEvoMedica.getText());
        ficha.getEvPsicologia().setEvolucao(this.areaEvoPsico.getText());
        ficha.getEvServSoc().setEvolucao(this.areaEvoSocial.getText());
        ficha.setHorMedicacao(this.areaHorario.getText());
        ficha.setPrescricao(this.areaPrescricao.getText());
        ficha.setProcRealizado(this.areaProc.getText());
        ficha.setConduta(this.campoConduta.getText());
        ficha.getEvMedica().setData(this.campoDataEvoMedica.getText());
        ficha.getEvServSoc().setData(this.campoDataEvoSocial.getText());
        ficha.getEvPsicologia().setData(this.campoDataEvoPsico.getText());
        ficha.setDiagnostico(this.campoDiag.getText());
        ficha.getEvMedica().setHora(this.campoHoraEvoMedica.getText());
        ficha.getEvPsicologia().setHora((this.campoHoraEvoPsico.getText()));
        ficha.getEvServSoc().setHora(this.campoHoraEvoSocial.getText());
        ArrayList<AplicacaoUrgencia> list = new ArrayList<>();
        DefaultTableModel d1 = (DefaultTableModel) this.tableQtd.getModel();
        for(int i = 0; i < tableQtd.getRowCount(); ++i){
            String aux[] = new String[5];
            for(int j = 0; j < tableQtd.getColumnCount(); ++j){
                aux[j] = (String) d1.getValueAt(i, j);
            }
            AplicacaoUrgencia p = new AplicacaoUrgencia(aux[0], aux[1], Integer.parseInt(aux[2]), aux[3], aux[4], "", "");
            list.add(p);
        }
        ficha.setAplic(list);
        MapasAtendPsiqUrgencia mapa = MapasAtendPsiqUrgencia.getInstance();
        ficha.setDestino(mapa.getDestino().get(comboDestino.getSelectedItem()));
        FichaAtendPsiqUrgenciaJpaController apuc = new FichaAtendPsiqUrgenciaJpaController();
        try {
            apuc.edit(ficha);
        } catch (NonexistentEntityException ex) {
            Logger.getLogger(TelaFichaAtendPsiqUrgencia2.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(TelaFichaAtendPsiqUrgencia2.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        campoDiag = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        campoConduta = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        areaPrescricao = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        areaHorario = new javax.swing.JTextArea();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        campoDataEvoMedica = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        campoHoraEvoMedica = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        areaEvoMedica = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();
        campoHoraEvoPsico = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        campoDataEvoPsico = new javax.swing.JTextField();
        jScrollPane4 = new javax.swing.JScrollPane();
        areaEvoPsico = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        campoHoraEvoSocial = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        campoDataEvoSocial = new javax.swing.JTextField();
        jScrollPane5 = new javax.swing.JScrollPane();
        areaEvoSocial = new javax.swing.JTextArea();
        jLabel13 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        tableQtd = new javax.swing.JTable();
        jLabel15 = new javax.swing.JLabel();
        jScrollPane7 = new javax.swing.JScrollPane();
        areaProc = new javax.swing.JTextArea();
        jLabel16 = new javax.swing.JLabel();
        comboDestino = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        botaoSalvar = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setText("Diagnóstico:");

        jLabel2.setText("Conduta:");

        jLabel3.setText("Prescrição:");

        areaPrescricao.setColumns(20);
        areaPrescricao.setRows(5);
        jScrollPane1.setViewportView(areaPrescricao);

        jLabel4.setText("Horário da Medicação:");

        areaHorario.setColumns(20);
        areaHorario.setRows(5);
        jScrollPane2.setViewportView(areaHorario);

        jLabel5.setText("Data:");

        campoDataEvoMedica.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoDataEvoMedicaKeyPressed(evt);
            }
        });

        jLabel6.setText("Hora:");

        campoHoraEvoMedica.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoHoraEvoMedicaKeyPressed(evt);
            }
        });

        jLabel7.setText("Evolução Médica:");

        areaEvoMedica.setColumns(20);
        areaEvoMedica.setRows(5);
        jScrollPane3.setViewportView(areaEvoMedica);

        jLabel8.setText("Hora:");

        campoHoraEvoPsico.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoHoraEvoPsicoKeyPressed(evt);
            }
        });

        jLabel9.setText("Data:");

        campoDataEvoPsico.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoDataEvoPsicoKeyPressed(evt);
            }
        });

        areaEvoPsico.setColumns(20);
        areaEvoPsico.setRows(5);
        jScrollPane4.setViewportView(areaEvoPsico);

        jLabel10.setText("Evolução Psicologia:");

        jLabel11.setText("Hora:");

        campoHoraEvoSocial.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoHoraEvoSocialKeyPressed(evt);
            }
        });

        jLabel12.setText("Data:");

        campoDataEvoSocial.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoDataEvoSocialKeyPressed(evt);
            }
        });

        areaEvoSocial.setColumns(20);
        areaEvoSocial.setRows(5);
        jScrollPane5.setViewportView(areaEvoSocial);

        jLabel13.setText("Evolução S. Social:");

        jLabel14.setText("Quantidade:");

        tableQtd.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Quantidade", "Medicamentos", "Dose", "Horário", "Evolução/Procedimento"
            }
        ));
        jScrollPane6.setViewportView(tableQtd);

        jLabel15.setText("Procedimentos Realizados:");

        areaProc.setColumns(20);
        areaProc.setRows(5);
        jScrollPane7.setViewportView(areaProc);

        jLabel16.setText("Destino do Paciente:");

        comboDestino.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Obs. 72h PA", "Consulta", "Medicado", "Residência", "Transf. Hosp. Clínico", "Transf. P/ Hosp. Psiq.", "Alta Médica", "Termo", "Evasão", "Óbito" }));

        jButton1.setText("< Anterior");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        botaoSalvar.setText("Salvar");
        botaoSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSalvarActionPerformed(evt);
            }
        });

        jButton3.setText("Cancelar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator4)
                    .addComponent(jSeparator3)
                    .addComponent(jSeparator2)
                    .addComponent(jSeparator1)
                    .addComponent(jScrollPane6)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel15)
                            .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 446, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(comboDestino, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel16)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botaoSalvar))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoDataEvoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoHoraEvoSocial)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel13)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane5))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoDataEvoPsico, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoHoraEvoPsico)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoDataEvoMedica, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel6)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoHoraEvoMedica)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel7)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 522, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel14)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE)
                                        .addComponent(campoDiag, javax.swing.GroupLayout.Alignment.LEADING))
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel4)
                                        .addComponent(campoConduta)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE)))))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoDiag, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoConduta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(campoDataEvoMedica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(campoHoraEvoMedica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(campoDataEvoPsico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(campoHoraEvoPsico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(campoDataEvoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(campoHoraEvoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel15))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(jLabel16)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(comboDestino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(botaoSalvar)
                            .addComponent(jButton3)))
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSalvarActionPerformed
        salvar();
    }//GEN-LAST:event_botaoSalvarActionPerformed

    private void campoDataEvoMedicaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoDataEvoMedicaKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoDataEvoMedica.setText(Formatador.formataData(campoDataEvoMedica.getText()));
        }
    }//GEN-LAST:event_campoDataEvoMedicaKeyPressed

    private void campoHoraEvoMedicaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoHoraEvoMedicaKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoHoraEvoMedica.setText(Formatador.formataHora(campoHoraEvoMedica.getText()));
        }
    }//GEN-LAST:event_campoHoraEvoMedicaKeyPressed

    private void campoDataEvoPsicoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoDataEvoPsicoKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoDataEvoPsico.setText(Formatador.formataData(campoDataEvoPsico.getText()));
        }
    }//GEN-LAST:event_campoDataEvoPsicoKeyPressed

    private void campoHoraEvoPsicoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoHoraEvoPsicoKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoHoraEvoPsico.setText(Formatador.formataHora(campoHoraEvoPsico.getText()));
        }
    }//GEN-LAST:event_campoHoraEvoPsicoKeyPressed

    private void campoDataEvoSocialKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoDataEvoSocialKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoDataEvoSocial.setText(Formatador.formataData(campoDataEvoSocial.getText()));
        }
    }//GEN-LAST:event_campoDataEvoSocialKeyPressed

    private void campoHoraEvoSocialKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoHoraEvoSocialKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoHoraEvoSocial.setText(Formatador.formataHora(campoHoraEvoSocial.getText()));
        }
    }//GEN-LAST:event_campoHoraEvoSocialKeyPressed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        TelaFichaAtendPsiqUrgencia.getInstance().limpaCampos();
        TelaFichaAtendPsiqUrgencia2.getInstance().limpaCampos();
        setVisible(false);   
    }//GEN-LAST:event_jButton3ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        TelaFichaAtendPsiqUrgencia.getInstance().limpaCampos();
        TelaFichaAtendPsiqUrgencia2.getInstance().limpaCampos(); 
    }//GEN-LAST:event_formWindowClosing

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        TelaFichaAtendPsiqUrgencia.getInstance().setVisible(true);
        setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    public FichaAtendPsiqUrgencia getFicha() {
        return ficha;
    }

    public void setFicha(FichaAtendPsiqUrgencia ficha) {
        this.ficha = ficha;
    }    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaFichaAtendPsiqUrgencia2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaFichaAtendPsiqUrgencia2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaFichaAtendPsiqUrgencia2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaFichaAtendPsiqUrgencia2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaFichaAtendPsiqUrgencia2().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea areaEvoMedica;
    private javax.swing.JTextArea areaEvoPsico;
    private javax.swing.JTextArea areaEvoSocial;
    private javax.swing.JTextArea areaHorario;
    private javax.swing.JTextArea areaPrescricao;
    private javax.swing.JTextArea areaProc;
    private javax.swing.JButton botaoSalvar;
    private javax.swing.JTextField campoConduta;
    private javax.swing.JTextField campoDataEvoMedica;
    private javax.swing.JTextField campoDataEvoPsico;
    private javax.swing.JTextField campoDataEvoSocial;
    private javax.swing.JTextField campoDiag;
    private javax.swing.JTextField campoHoraEvoMedica;
    private javax.swing.JTextField campoHoraEvoPsico;
    private javax.swing.JTextField campoHoraEvoSocial;
    private javax.swing.JComboBox comboDestino;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JTable tableQtd;
    // End of variables declaration//GEN-END:variables
    private FichaAtendPsiqUrgencia ficha;
    private static TelaFichaAtendPsiqUrgencia2 instance = null;
}
